import formatColumn from 'packages/BaseTableCell/formatColumn'
import { isUndefined } from '@src/util/type'
import i18n from '@src/locales'
const SortFieldNames = ['createTime', 'nextTaskCreateTime', 'createdTasks']


// 列表 && 选择列
export const getColumnFields = (vm, type) => {
  const that = vm;
  const customerField = that.customerField || {}
  const customerOption = customerField?.setting?.customerOption || {}
  
  return [
    {
      fieldName: 'planNumber',
      displayName: i18n.t('common.fields.planNumber.displayName'),
      formType: 'text'
    },
    {
      fieldName: 'name',
      displayName: i18n.t('common.fields.taskName.displayName'),
      formType: 'text'
    },
    {
      fieldName: 'state',
      displayName: i18n.t('task.taskTypes.planTask.taskStatus'),
      formType: 'text'
    },
    {
      displayName: i18n.t('common.task.taskType'),
      fieldName: 'templateName',
      formType: 'select'
    },
    {
      fieldName: 'period',
      displayName: i18n.t('common.fields.repetitionPeriod.displayName'),
      formType: 'text'
    },
    {
      fieldName: 'customer',
      displayName: i18n.t('common.base.customer'),
      formType: 'text'
    },
    {
      fieldName: 'tlmName',
      displayName: i18n.t('common.base.contact'),
      formType: 'select',
      show: customerOption.linkman,
      visibleForSelectColumn: customerOption.linkman,
    },
    {
      fieldName: 'tlmPhone',
      displayName: i18n.t('common.base.phone'),
      formType: 'select',
      show: customerOption.linkman,
      visibleForSelectColumn: customerOption.linkman
    },
    {
      fieldName: 'taddressStr',
      displayName: i18n.t('common.form.type.customerAddress'),
      formType: 'address',
      show: customerOption.address,
      visibleForSelectColumn: customerOption.address
    },
    {
      fieldName: 'createRule',
      displayName: i18n.t('task.edit.generateRules.label'),
      formType: 'text',
    },
    ,
    {
      fieldName: 'headName',
      displayName: i18n.t('task.executor'),
      formType: 'user'
    },
    {
      fieldName: 'createUser',
      displayName: i18n.t('common.base.createUser'),
      formType: 'user'
    },
    {
      fieldName: 'createTime',
      displayName: i18n.t('common.base.createTime'),
      formType: 'datetime',
    },
    {
      fieldName: 'end',
      displayName: i18n.t('common.fields.deadline.displayName'),
      formType: 'datetime',
      sortable: false,
    },
    {
      fieldName: 'dispatchSettings',
      displayName: i18n.t('task.taskTypes.planTask.dispatchSettings'),
      formType: 'text'
    }
  ].map(item => {
    // 初始化属性
    let field = {
      ...item,
      setting: item.setting || {},
      isSystem: 1,
      isNull: 1,
      isSearch: 1,
      orderId: 1,
      show: isUndefined(item.show) ? true : item.show,
      visibleForSelectColumn: isUndefined(item.visibleForSelectColumn) ? true : item.visibleForSelectColumn,
    };
    return formatColumn(field, SortFieldNames, []); 
  })
};

// 产品关联字段 - 目前只返回产品编号，产品类型，因为后端目前就是这两个返回了值
export const getProductRelation = () => {
  return [{
    fieldName: 'serialNumber',
    displayName: i18n.t('common.product.productNo'),
    formType: 'text'
  }, {
    fieldName: 'type',
    displayName: i18n.t('common.product.productType'),
    formType: 'text'
  },]
}